﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace Othello
{
    
    public enum LocationValue { empty, black, white };

    public class Board
    {
        private static int dimension_size = 8;
        bool?[,] _board = new bool?[dimension_size, dimension_size];
        public Board()
        {

        }

        public LocationValue GetLocationValue(int x, int y)
        {
            CheckCoord(x);
            CheckCoord(y);
            return LVbooltoEnum(_board[x, y]);
        }

        public void SetLocationValue(int x, int y, LocationValue value) {
            CheckCoord(x);
            CheckCoord(y);
            _board[x, y] = LVEnumtobool(value);
        }

        private LocationValue LVbooltoEnum(bool? nullable)
        {
            switch (nullable)
            {
                case null: return LocationValue.empty;
                case true: return LocationValue.black;
                case false: return LocationValue.white;
                default: return LocationValue.empty; // should never be reached.
            }
        }

        private bool? LVEnumtobool(LocationValue value)
        {
            switch (value)
            {
                case LocationValue.empty: return null;
                case LocationValue.black: return true;
                case LocationValue.white: return false;
                default: return null;
            }
        }

         public void CheckCoord(int y)
        {
            if (y < 0 || y > dimension_size - 1) throw new Exception("Illegal board coordinate: " + y);
        }
    }
}
